<?PHP if( ! defined('BASEPATH')) exit('Sorry, no direct script allowed.');

class Modelsqlite
{
	protected 
	
	$mydb = NULL;
	
	function _get_connected()
	{
		try
		{
			$this->mydb = new PDO($config['dbdriver']. ":" . $config['default_db']);
			$this->mydb->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 
		}
		catch(PDOException $e)
		{
			log_message('error', $e->getMessage());
			
			file_put_contents('PDOErrors.txt', 
				mktime(time()) .': '. $e->getMessage(), FILE_APPEND);
				
			if($this->db_debug)
			{
				$this->display_error($error, '', TRUE);
				return FALSE;
			}
		}
		
		return $this->mydb;
		
	}
	
	function db_connect()
	{
		return $this->_get_connected();
	}
	
	function db_close()
	{
		return $this->_get_disconnected();
	}
	
	function _get_disconnected()
	{
		$this->mydb = NULL;
	}
	
	function __construct()
	{
		require_once APPPATH."config/restdb.php";
		
		$config['dbdriver'] = "sqlite";
		$config['default_db'] = $restdb['database'];
	}

}
